<script>
export default {
  name: 'ElementItem',
  props: {
    element: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isActive: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  methods: {
    clickEvent(element) {
      this.$emit('click-clement', element)
    },
    clickUp() {
      this.$emit('click-up', this.element)
    },
    clickDown() {
      console.log('clickDown')
      this.$emit('click-down', this.element)
    },
    clickDelete() {
      this.$emit('click-delete', this.element)
    }
  }
}
</script>

<template>
  <div :class="{'element-item': true,'is-active': isActive}" @click="()=> clickEvent(element)">
    <i class="el-icon-connection" />
    <span style="margin-left: 5px">{{ element.label }}</span>
    <span class="cm-operator">
      <i class="el-icon-top" @click="clickUp" />
      <i class="el-icon-bottom" @click="clickDown" />
      <i class="el-icon-delete" @click="clickDelete" />
    </span>
  </div>
</template>

<style scoped lang="scss">
.element-item {
  height: 32px;
  margin-top: 10px;
  width: 100%;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  padding-left: 5px;
  color: #606266;
  font-size: 13px;
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
}

.element-item:hover {
  border: 1px solid #409eff;
}

.is-active {
  border: 1px solid #409eff;
}

.cm-operator {
  position: absolute;
  height: 100%;
  padding: 5px;
  right: 0;
  align-items: center;
  justify-content: flex-end;
  display: none;
}

.element-item:hover .cm-operator {
  display: flex;
}

.cm-operator i {
  margin-left: 5px;
  cursor: pointer;
}

.cm-operator i:hover {
  color: #409eff;
}

.el-icon-connection {
  font-size: 16px;
  color: #909399;
}
</style>
